package com.hqj.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.hqj.dao.CommentMapper;
import com.hqj.entity.Comment;
import com.hqj.service.CommentService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author 黄啟军
 * @version 1.0
 * @date 2020/8/2 0002
 */
@Service
public class CommentServiceImpl implements CommentService {
    @Resource
    private CommentMapper commentMapper;

    @Override
    public int saveComment(Comment comment) {
        return commentMapper.insert(comment);
    }
    @Override
    public List<Comment> selectAll(Long id) {
        QueryWrapper<Comment> queryWrapper1 = new QueryWrapper<>();
        queryWrapper1.eq("blog_id",id);
        queryWrapper1.eq("parent_id",0);
        List<Comment> commentList = commentMapper.selectList(queryWrapper1);
        for (Comment comment :commentList){
            QueryWrapper<Comment> queryWrapper = new QueryWrapper<>();
            queryWrapper.eq("parent_id",comment.getId());
            List<Comment> comments1 = commentMapper.selectList(queryWrapper);
            comment.setCommentList(comments1);
            queryWrapper=null;
        }
        return commentList;
    }
}
